<template>
  <div class="user-page" v-if="user.userInfo.account">
    <!-- 头像部分 -->
    <div class="user-page-head">
      <div class="top">
        <van-image round :src="user.userInfo.avatar" />
        <div class="name">
          <p>{{ user.userInfo.account }}</p>
          <p>
            <van-icon name="edit" />
          </p>
        </div>
      </div>
      <van-row>
        <van-col span="6">
          <p>{{ user.userInfo.collectionNumber }}</p>
          <p>收藏</p>
        </van-col>
        <van-col span="6"
          ><p>{{ user.userInfo.likeNumber }}</p>
          <p>关注</p></van-col
        >
        <van-col span="6"
          ><p>{{ user.userInfo.score }}</p>
          <p>积分</p></van-col
        >
        <van-col span="6"
          ><p>{{ user.userInfo.couponNumber }}</p>
          <p>优惠券</p></van-col
        >
      </van-row>
    </div>
    <!-- 订单部分 -->
    <div class="user-page-order">
      <div class="head">
        <h3>药品订单</h3>
        <router-link to="/order"
          >全部订单
          <van-icon name="arrow" />
        </router-link>
      </div>
      <van-row>
        <van-col span="6">
          <p>
            <van-badge
              :content="user.userInfo.orderInfo.paidNumber"
              :show-zero="false"
            >
              <icon class="cp-icon" name="user-paid" />
            </van-badge>
          </p>
          <p>待付款</p>
        </van-col>
        <van-col span="6"
          ><p>
            <van-badge
              :content="user.userInfo.orderInfo.shippedNumber"
              :show-zero="false"
            >
              <icon class="cp-icon" name="user-shipped" />
            </van-badge>
          </p>
          <p>待发货</p></van-col
        >
        <van-col span="6"
          ><p>
            <van-badge
              :content="user.userInfo.orderInfo.receivedNumber"
              :show-zero="false"
            >
              <icon class="cp-icon" name="user-received" />
            </van-badge>
          </p>
          <p>待收货</p></van-col
        >
        <van-col span="6"
          ><p>
            <van-badge
              :content="user.userInfo.orderInfo.finishedNumber"
              :show-zero="false"
            >
              <icon class="cp-icon" name="user-finished" />
            </van-badge>
          </p>
          <p>已完成</p></van-col
        >
      </van-row>
    </div>
    <!-- 快捷工具 -->
    <div class="user-page-group">
      <h3>快捷工具</h3>
      <van-cell title="我的问诊" is-link to="/my/consult">
        <template #icon>
          <icon class="cp-icon" name="user-tool-01" />
        </template>
      </van-cell>
      <van-cell title="我的处方" is-link>
        <template #icon>
          <icon class="cp-icon" name="user-tool-02" />
        </template>
      </van-cell>
      <van-cell title="家庭档案" is-link to="/my/patient">
        <template #icon>
          <icon class="cp-icon" name="user-tool-03" />
        </template>
      </van-cell>
      <van-cell title="地址管理" is-link>
        <template #icon>
          <icon class="cp-icon" name="user-tool-04" />
        </template>
      </van-cell>
      <van-cell title="我的评价" is-link>
        <template #icon>
          <icon class="cp-icon" name="user-tool-05" />
        </template>
      </van-cell>
      <van-cell title="官方客服" is-link>
        <template #icon>
          <icon class="cp-icon" name="user-tool-06" />
        </template>
      </van-cell>
      <van-cell title="设置" is-link>
        <template #icon>
          <icon class="cp-icon" name="user-tool-07" />
        </template>
      </van-cell>
    </div>
    <!-- 退出 -->
    <a class="logout" href="javascript:void;" @click="logout"> 退出登录</a>
  </div>
</template>

<script lang="ts" setup>
import { Dialog } from 'vant'
import { useRouter } from 'vue-router'
import { onMounted } from 'vue'
import useStore from '@/store'
const router = useRouter()
const { user, login } = useStore()
onMounted(() => {
  user.getUserInfo()
})
const logout = () => {
  Dialog.confirm({
    title: '提示',
    message: '确定退出吗?'
  })
    .then(() => {
      // on confirm
      user.logout()
      login.logout()

      // 跳转到登录页
      router.push('/login')
    })
    .catch(() => {
      // on cancel
    })
}
</script>

<style lang="scss" scoped>
.user-page {
  background-color: var(--cp-bg);
  min-height: calc(100vh - 50px);
  padding: 0 15px 65px;
  // 头部
  &-head {
    height: 200px;
    background: linear-gradient(
      180deg,
      rgba(44, 181, 165, 0.46),
      rgba(44, 181, 165, 0)
    );
    margin: 0 -15px;
    padding: 0 15px;
    .top {
      display: flex;
      padding-top: 50px;
      align-items: center;
      .van-image {
        width: 70px;
        height: 70px;
      }
      .name {
        padding-left: 10px;
        p {
          &:first-child {
            font-size: 18px;
            font-weight: 500;
          }
          &:last-child {
            margin-top: 10px;
            color: var(--cp-primary);
            font-size: 16px;
          }
        }
      }
    }
    .van-row {
      margin: 0 -15px;
      padding-top: 15px;
      p {
        text-align: center;
        &:first-child {
          font-size: 18px;
          font-weight: 500;
        }
        &:last-child {
          color: var(--cp-dark);
          font-size: 12px;
          padding-top: 4px;
        }
      }
    }
  }
  // 订单
  &-order {
    background-color: #fff;
    border-radius: 8px;
    margin-bottom: 15px;
    padding-bottom: 15px;
    .head {
      display: flex;
      justify-content: space-between;
      line-height: 50px;
      padding: 0 15px;
      a {
        color: var(--cp-tip);
      }
    }
    .van-col {
      text-align: center;
      .cp-icon {
        font-size: 28px;
      }
      p {
        font-size: 12px;
        padding-top: 4px;
      }
    }
  }
  // 分组
  &-group {
    background-color: #fff;
    border-radius: 8px;
    overflow: hidden;
    h3 {
      padding-left: 16px;
      line-height: 44px;
    }
    .van-cell {
      align-items: center;
    }
    .cp-icon {
      font-size: 17px;
      margin-right: 10px;
    }
  }
  .logout {
    display: block;
    margin: 20px auto;
    width: 100px;
    text-align: center;
    color: var(--cp-price);
  }
}
</style>
